package tools

import (
	"fmt"
	"github.com/xuri/excelize/v2"
	"log"
)

var ShapeDict map[string]string

func GetShapeTypeBy(file string) map[string]string {
	resultData := make(map[string]string)
	_, rows, cols, err := GetSheetRows(file)
	if err != nil {
		log.Println(err)
	}
	for cindex, coln := range cols {
		for index, rown := range coln {
			if index != 0 {
				if rown == "" {
					break
				}
				resultData[rown] = rows[0][cindex]
			}
		}
	}
	return resultData

}
func GetSheetRows(path string) ([]string, [][]string, [][]string, error) {
	var err error
	f, err := excelize.OpenFile(path)
	if err != nil {
		fmt.Println(err)
		return nil, nil, nil, err
	}
	defer func() {
		// Close the spreadsheet.
		if err := f.Close(); err != nil {
			fmt.Println(err)
		}
	}()

	// Get all the rows in the Sheet1.
	sheetList := f.GetSheetList()
	//log.Println(sheetList)
	rows, err := f.GetRows(sheetList[0])
	cols, err := f.GetCols(sheetList[0])
	if err != nil {
		fmt.Println(err)
		return nil, nil, nil, err
	}
	return sheetList, rows, cols, nil
}
